<template>
    <div class="clinicPayment">
        <!--  -->
        <header>
            <Row>
                <Col>
                    <div class="margin-up-down">
                        <span>开始日期</span>
                        <DatePicker type="date" v-model="getParams.startDate" style='width:120px;'></DatePicker>
                    </div>
                    <div class="margin-up-down">
                        <span>结束日期</span>
                        <DatePicker type="date" v-model="getParams.endDate" style='width:120px;'></DatePicker>
                    </div>
                    <div class="margin-up-down">
                        <Button type='success' @click='query(1)'>查询</Button>
                    </div>
                </Col>
            </Row>
        </header>
        <Table stripe :row-class-name="rowClassName" :columns="columns1" :data="data1" style='margin:10px 0;'></Table>
        <div class="page">
            <Page :total="count" :current='pageNo' :page-size="pageSize" show-total show-elevator @on-change="pageChange"/>
        </div>
        
    </div>
</template>
<script>
import api from "@/api/commonApi";
import { DatePicker, TimePicker, Card, Progress } from 'view-design'
// 诊间交费
export default {
    components: {
        DatePicker,
        TimePicker,
        Card,
        Progress
    },
    data () {
        return {
            // ORDER_TYPE_ENUM:[
            //   {code:0,name:'挂号'},
            //   {code:1,name:'互联网缴费'},
            // ],
          // ORDER_TYPE_ENUM:[{code:0,name:'健康咨询'},{code:1,name:'巡诊'},{code:2,name:'复诊'},{code:6,name:'预约挂号'},{code:11,name:'诊间缴费'},{code:22,name:'互联网缴费'}],
            ORDER_TYPE_ENUM:[
              {code:0,name:'健康咨询'},
              {code:1,name:'巡诊'},
              {code:2,name:'复诊'},
              {code:3,name:'续方'},
              {code:4,name:'用药咨询'},
              {code:5,name:'购药'},
              {code:6,name:'预约挂号'},
              {code:7,name:'家医签约'},
              {code:8,name:'远程门诊'},
              {code:9,name:'直播'},
              {code:10,name:'点播'},
              {code:11,name:'诊间缴费'},
              {code:12,name:'充值'},
              {code:13,name:'住院押金缴费'},
              {code:14,name:'院后随访'},
              {code:15,name:'外延处方'},
              {code:16,name:'远程会诊'},
              {code:17,name:'病历复印'},
              {code:18,name:'检查检验预约'},
              {code:19,name:'检查预约'},
              {code:20,name:'检验预约'},
              {code:21,name:'体检预约'},
              {code:22,name:'互联网缴费'},
              {code:23,name:'手术预约'},
              {code:30,name:'线上就诊'}
            ],
            // 头部参数
            getParams: {
                // 开始时间
                startDate: '',
                startTime: "00:00",
                // 结束时间
                endDate: "",
                endTime: "",
                // 查询条件
                searchKey:"",
                // 异常
                single : false,
            },
            // 列表数据
            columns1: [],
            data1: [],
            // 分页数据
            count: 0,
            pageNo: 1,
            pageSize: 10,
            // 弹窗状态
            clinicStatus: false,
            // 单个平台状态列表
            statusList: ['失败','交易成功','退费', '未获取到状态'],
            //支付渠道
            Channels:['微信','支付宝','线下支付','就诊卡号'],
            // 点击来源
            buttonStatus: 1,
            orderStatusList: [
                {
                    name: "支付成功",
                    id:'1'
                },
                {
                    name: "未支付",
                    id:'2'
                },
                {
                    name: "支付失败",
                    id:'3'
                },
                {
                    name: "支付取消",
                    id:'4'
                },
                {
                    name: "已退费",
                    id:'5'
                },
            ],
            // 订单对账状态
            manualParams: {
                // 平台状态
                PlatformStatus: '已支付',
                // 互联网平台状态
                interPlatformStatus: "",
                // HIS状态
                hisPlatformStatus: "",
                // 弹窗查询流水号
                modalSearchKey:"",
                // id
                transId:""
            },
            stautParams: ['未对账','对账成功','未获取到数据','金额不符','状态不符'],
            // // 自动对账状态
            autoLoad:false,
            // 进度条
            progressStart: 0,
            uuid :'',
            DZdisabled: false,
        }
    },
    created () {
        this.columns1 = [
            {
                key: "isum",
                title: "排序",
                align: "center",
                width:60,
                render: (h, params) => {
                    let isum = (this.pageNo-1)*this.pageSize + params.index +1;
                    return h("span", isum);
                }
            },
            {
                key: "dataTime",
                title: "对账日期",
                align: "center"
                // width: 100,
            },
            {
                key: "hospitalName",
                title: "医院",
                align: "center"
                // width: 100,
            },
            {
                key: "businessType",
                title: "业务类型",
                align: "center",
                render: this.findTypeName
            },
            {
                key: "orderQuantity",
                title: "订单数量",
                align: "center"
            },
            {
                key: "wholeAccountMoney",
                title: "统筹金额",
                align: "center"
            },
            {
                key: "personalAccountMoney",
                title: "个人帐户金额",
                align: "center"
            },
            {
                key: "wechatMoney",
                title: "微信金额",
                align: "center"
            },
            {
                key: "sumsMoney",
                title: "总金额",
                align: "center"
            },
            {
              key: "orderQuantityRefund",
              title: "退款数量",
              align: "center"
            },
            {
              key: "sumsMoneyRefund",
              title: "退款金额",
              align: "center"
            },
        ];
        
        this.getParams.startDate = this.GetDate(0);
        this.getParams.endDate = this.GetDate(0);
        let date = new Date();
        this.getParams.endTime = date.getHours() + ':' + date.getMinutes()
        //this.$emit("changeBreadList", breadList);
    },
    mounted () {
        this.loadingCardRechargeList(this.pageNo)
    },
    methods: {
        findTypeName(h, params) {
            let record = params.row;
            let typeName = "";
            //找到名字
            for(let i=0;i<this.ORDER_TYPE_ENUM.length;i++){
                // if( record.businessType < 7 ){
                //     typeName = this.ORDER_TYPE_ENUM[0].name;
                //     break;
                // } else {
                //     typeName = this.ORDER_TYPE_ENUM[1].name;
                //     break;
                // }
                if( this.ORDER_TYPE_ENUM[i].code==record.businessType){
                  typeName = this.ORDER_TYPE_ENUM[i].name;
                  break;
                }
            }
            return [
                h("span", typeName)
            ]
        },
        query () {
            this.loadingCardRechargeList(this.pageNo);
        },
        // 分页器改变
        pageChange (index) {
            this.pageNo = index;
            this.loadingCardRechargeList(index)
        },
                
        // 加载页面列表数据
        loadingCardRechargeList (pageNo) {
            /*
                加载页面列表对账信息
            */
            this.pageNo = pageNo
            let url = api.statFinanceDayinfo
            let startTime = this.getData(this.getParams.startDate);
            let endTime = this.getData(this.getParams.endDate);
            let params = {
                pageNo: pageNo,
                pageSize: this.pageSize,
                startDate: this.getParams.startDate,
                endDate: this.getParams.endDate
            }
            
            if(this.getParams.startDate === '' || this.getParams.startDate === null){
                delete params.startDate
            }
            if(this.getParams.endDate === '' || this.getParams.endDate === null){
                delete params.endDate
            }
            this.$axios.post(url,params).then(ress => {
                if(ress.data.success) {
                    let ret = ress.data.object;
                    this.count = ret.total
                    console.log(ret);
                    if(ret.records){
                        ret.records.forEach((item, index) => {
                            item.isum = this.addZeros(index)
                        })
                        this.data1 = ret.records
                    } else {
                        this.data1 = []
                    }
                } else {
                    this.$Message.info("请确认当前账号是否绑定机构")
                }
            })
        },
        // 转换日期格式
        getData(data){
            let datas = new Date(data)
            var curr_date = datas.getDate();
            var curr_month = datas.getMonth() + 1;
            var curr_year = datas.getFullYear();
            function add(num){
                if(Number(num)<10) {
                    return '0' + num
                }
                return num
            }
            return curr_year + "-" + add(curr_month)+'-' + add(curr_date)
        }
    }
};
</script>

<style lang="less" scoped>
.clinicPayment {
    width: calc(100%);
    padding: 10px 30px;
    margin: 0 auto;
    background: #fff;
    .margin-up-down {
        display: inline-block;
        margin-top: 10px;
    }
    .page{
        text-align: center;
        margin-top: 20px;
    }
}
</style>
<style>
.ivu-table .demo-error-row td{
    color: red;
}
.ivu-table .demo-error-row td a{
    color:red
}
.ivu-table .demo-success-row td{
    color: #2b85e4;
}
.ivu-table .demo-success-row td a{
    color:#2b85e4
}
</style>
